import { createStore } from 'vuex'
import { getMusicLyric } from '@/Api/request.js'

export default createStore({
  state: {
    playList: [
      {
        name: '彩券',
        al: {
          id: 96680121,
          name: '彩券',
          pic: 109951165386012140,
          picUrl: 'http://p3.music.126.net/NP1Zg57UUbHNzAhw7n-LeA==/109951165386012146.jpg'
        },
        id: 1486513704,
        ar: ['name']
      }
    ],
    playCurrentIndex: 0,
    lyric: ''
  },
  getters: {
    lyricList: function (state) {
      let arr = state.lyric.split(/\n/gis).map((item, i) => {
        let min = item.slice(1, 3)
        let sec = item.slice(4, 6)
        let mill = item.slice(7, 10)
        return {
          min,
          sec,
          mill,
          lyric: item.slice(11, item.length)
        }
      })
      return arr
    }
  },
  mutations: {
    setPlayList: function (state, value) {
      state.playList = value
    },
    pushPlayList: function (state, value) {
      state.playList.push(value)
    },

    setPlayCurrentIndex: function (state, value) {
      state.playCurrentIndex = value
    },
    setLyric(state, value) {
      state.lyric = value
    }
  },
  actions: {
    async reqLyric(content, payload) {
      const { data: res } = await getMusicLyric(payload.id)
      content.commit('setLyric', res.lrc.lyric)
    }
  },
  modules: {}
})
